Ext.define('hkyg.view.LoginWin', {
  	  extend: 'Ext.window.Window',
  	  alias: 'widget.loginWin',
	  title: '后台入口',
	  closable: false,
	  width: 300,
	  height: 200,
	  layout: 'fit',
	  initComponent: function() {
		  var me = this;
		  me.items = [{
				xtype: 'form',
				url: 'hkyg/Background.do?method=login',
				layout: 'anchor',
			    border: 0,
			    defaults: {
			    	xtype: 'textfield',
			    	labelAlign: 'right',
			    	labelStyle: 'font-size:15px',
			    	labelWidth: 60,
			    	width: 100,
			    	height: 30,
			    	anchor: '100%',
			    	margin: '15,0,0,0'
			    },
			    items: [{
			        fieldLabel: '用户名',
			        name: 'user_name',
			        blankAllow: false
			    },{
			        fieldLabel: '密码',
			        name: 'password',
			        inputType: 'password',
			        enableKeyEvents: true,
			        listeners: {
			        	keypress: function(scope, e) {
							if(e.keyCode == e.ENTER || e.keyCode == 10) {
								me.login();
							}
			        	}
			        }
			    },
			    {
			    	xtype: 'panel',
			    	layout: 'hbox',
			    	border: 0,
			    	
			    	margin: '20 0 0 55',
			    	defaults: {
			    		margin: '0 18 0 25',
			    		height: 30,
			    		flex: 1
			    	},
			    	items: [{
				    	xtype: 'button',
				        text: '<font size=2>登录</font>',
				        formBind: true, //only enabled once the form is valid
				        handler: function() {
				        	me.login();
				        }
				    }]
			    }],
			    renderTo: Ext.getBody()
			}];
		  me.callParent(arguments);
	  },
	  login: function() {
		  var me = this;
//		  var psdFld = me.down('textfield[name=password]');
//		  psdFld.setValue(hex_md5(psdFld.getValue()));
          var form = me.down('form').getForm();
          if (form.isValid()) {
              form.submit({
                  success: function(form, action) {
                	current_user_name = me.down('textfield[name=user_name]').getValue();
                	current_user_authority = action.result.data;
                  	me.fireEvent('loginSuccess');
                  	me.close();
                  },
                  failure: function(form, action) {
                      Ext.Msg.alert('提示', '密码输入有误');
                  }
              });
          }
	  }
});